import time

from selenium.webdriver.common.by import By
from base.base import Base

# ----------------操作员管理----------------

class page_operator_management(Base):

    def getloginname(self):
        self.switch_node('operator_management')
        return self.text('get_login_name')

    def op(self):
        self.switch_node('operator_management')
        self.click('op_manage')
        self.logger.info("点击操作员管理")

    # 精准查询
    def accurate_query(self,login_name):
        self.switch_node('operator_management')
        self.click('op_manage')
        self.logger.info("点击操作员管理")
        self.send_keys('op_login_name_input',login_name)
        self.click('op_select_button')

    # 模糊查询
    def fuzzy_query(self,name):
        self.switch_node('operator_management')
        self.click('op_manage')
        self.logger.info("点击操作员管理")
        self.send_keys('op_name_input',name)
        self.click('op_select_button')

    # 添加操作员
    def add_op(self,name,loginname,pwd,phone,desc):
        self.switch_node('operator_management')
        self.click('op_manage')
        self.logger.info("点击操作员管理")
        dy1=self.text('op_add')
        assert '添加' in dy1
        self.click('op_add')
        self.logger.info("点击添加操作员")
        dy2=self.text('op_yq2')
        assert '添加操作员' in dy2
        self.send_keys('op_name',name)
        self.logger.info("输入操作员姓名")
        self.send_keys('op_login_name',loginname)
        self.logger.info("输入操作员登录名")
        self.send_keys('op_login_pwd',pwd)
        self.logger.info("输入操作员密码")
        self.send_keys('op_phone',phone)
        self.click('op_login_status')
        time.sleep(2)
        self.click('op_activated')
        self.send_keys('op_desc',desc)
        self.scrollto_height()
        self.click('op_user')
        self.logger.info("选择角色")
        self.click('op_save')
        self.logger.info('点击保存')
        self.click('ok')

    # 修改操作员
    def update_op_(self,name,phone,desc):
        self.switch_node('operator_management')
        self.click('op_manage')
        self.logger.info("点击操作员管理")
        dy1 = self.text('op_add')
        assert '添加' in dy1
        self.click('op_update')
        self.logger.info("点击修改")
        self.send_keys('up_name',name)
        self.logger.info("修改用户名")
        self.send_keys('up_phone',phone)
        self.logger.info("修改手机号")
        self.scrollto_height()
        self.send_keys('up_desc',desc)
        self.logger.info("修改描述")
        self.click('up_user')
        self.logger.info("修改角色")
        self.click('up_save')
        self.logger.info('点击保存')
        self.click('ok')

    # 重置密码
    def uodate_pwd(self,pwd1,pwd2):
        self.switch_node('operator_management')
        self.click('op_manage')
        self.logger.info("点击操作员管理")
        dy1 = self.text('op_add')
        assert '添加' in dy1
        self.click('reset_password')
        self.logger.info("点击重置密码")
        pwd_dy1=self.text('reset_password_yq')
        assert '重置' in pwd_dy1
        self.send_keys('pwd_01',pwd1)
        self.logger.info("输入新密码")
        self.send_keys('pwd_02',pwd2)
        self.logger.info("再次输入新密码")
        self.click('pwd_save')
        self.logger.info("点击保存")
        self.click('ok')

    # 冻结/激活操作员
    def freeze_operator(self):
        self.switch_node('operator_management')
        self.click('qx_manage')
        self.logger.info("点击权限管理")
        self.click('op_manage')
        self.logger.info("点击操作员管理")
        dy1 = self.text('op_add')
        assert '添加' in dy1
        self.click('op_frozen')
        self.logger.info("点击冻结")
        self.click('frozen_yes')
        self.logger.info("点击确定")
        self.click('ok')
    # 退出系统
    def exit_system(self):
        self.switch_node('operator_management')
        self.click('freeze_system')


